package com.sx.baseproject.framework.model

import android.util.Log
import com.example.mvvm.base.annotation.Dialog
import com.example.mvvm.base.vm.BaseViewModel
import com.sx.baseproject.framework.net.HttpManager
import com.sx.baseproject.framework.net.base.ApiResponseConsumer
import com.sx.baseproject.framework.net.response.TestBean
import com.sx.baseproject.framework.net.response.TestList
import io.reactivex.Observable
import io.reactivex.Observer
import io.reactivex.functions.Consumer

/**
 * @Description
 * @Author 梁浩文
 * @Date 2021/6/25 11:46
 */
class MainModel : BaseViewModel() {
    fun getBean() {
        HttpManager.getInstance(false)
            .getBean()
            .doOnSubscribe { this }
            .subscribe(object : ApiResponseConsumer<TestBean>() {
                override fun onNext(t: TestBean) {
                    Log.i("MainModel", t.records.size.toString())
                }
            })
    }

    @Dialog
    fun getList() {
        HttpManager.getInstance(false)
            .getListBean()
            .doOnSubscribe(this)
            .subscribe(object : ApiResponseConsumer<MutableList<TestList>>() {
                override fun onNext(t: MutableList<TestList>) {
                    ui.hideDialog()
                    Log.i("MainModel", t.size.toString())
                }

                override fun onError(e: Throwable) {
                    super.onError(e)
                    ui.hideDialog()
                }

            })
    }
}